#pragma once

#include <vector>

#include "SequenceStream.h"
#include "OrderedMessage.h"
#include "Status.h"

namespace streamdb {

class MemoryStream : public SequenceStream<OrderedMessage>{
public:
    ~MemoryStream();
    Status append(const OrderedMessage & obj) override;
    uint64_t getSize() const override ;

    class iterator : public Iterator<OrderedMessage>{
    public:
        iterator(const std::vector<OrderedMessage>::iterator & cur, const std::vector<OrderedMessage>::iterator & end) ;
        ~iterator() override;

        iterator(const iterator & other)  = delete;
        iterator & operator=(const iterator & other) = delete;

        bool hasNext() const override;
        OrderedMessage & next() override;

    private:
        std::vector<OrderedMessage>::iterator cur; 
        std::vector<OrderedMessage>::iterator end; 
    };

    std::shared_ptr<SequenceStream<OrderedMessage>::IteratorType> advance(int64_t offset) override;
    std::shared_ptr<SequenceStream<OrderedMessage>::IteratorType> begin() override;

private:
    std::vector<OrderedMessage> msgs;
};
}//namespace streamdb
